<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-productDetail-add" enctype="multipart/form-data">
			<div class="form-group">	
				<label class="col-sm-3 control-label">产品溯源码：</label>
				<div class="col-sm-8">
			    	<input class="form-control" type="text" id="productCode" name="productCode" readonly="true" th:value="${productCode}">
					<!-- <input id="productCode" name="productCode" class="form-control" type="text"> -->
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">流程类型：</label>
				<div class="col-sm-8">
					<select id="processType" name="processType" class="form-control m-b" th:with="type=${@dict.getType('gh_process_type')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">操作说明：</label>
				<div class="col-sm-8">
					<input id="descInfo" name="descInfo" class="form-control" type="text">
				</div>
			</div>
			
		
			
			<div class="form-group">	
				<label class="col-sm-3 control-label">操作人：</label>
				<div class="col-sm-8">
					<input id="opeUser" name="opeUser" class="form-control" type="text">
				</div>
			</div>
	<!-- 		<div class="form-group">	
				<label class="col-sm-3 control-label">操作时间：</label>
				<div class="col-sm-8">
					<input id="opeTime" name="opeTime" class="form-control" type="text">
				</div>
			</div> -->
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remarks" name="remarks" class="form-control" type="text">
				</div>
			</div>
			
			<div class="form-group">	
			   <label class="col-sm-3 control-label">图片1：</label>
				<div class="col-sm-8">
			     <img id="image1" name="image1" value='custom' alt=" " data-address='' height="150" width="150"/>
			     <input type="file" id="chooseImage1" name="file1" >
                 </div>
            </div>
            	<div class="form-group">	
			   <label class="col-sm-3 control-label">图片2：</label>
				<div class="col-sm-8">
			     <img id="image2" name="image2" value='custom' alt=" " data-address='' height="150" width="150"/>
			     <input type="file" id="chooseImage2" name="file2" >
                 </div>
            </div>
            	<div class="form-group">	
			   <label class="col-sm-3 control-label">图片3：</label>
				<div class="col-sm-8">
			     <img id="image3" name="image3" value='custom' alt=" " data-address='' height="150" width="150"/>
			     <input type="file" id="chooseImage3" name="file3" >
                 </div>
            </div>
            	<div class="form-group">	
			   <label class="col-sm-3 control-label">图片4：</label>
				<div class="col-sm-8">
			     <img id="image4" name="image4" value='custom' alt=" " data-address='' height="150" width="150"/>
			     <input type="file" id="chooseImage4" name="file4" >
                 </div>
            </div>
            	<div class="form-group">	
			   <label class="col-sm-3 control-label">图片5：</label>
				<div class="col-sm-8">
			     <img id="image5" name="image5" value='custom' alt=" " data-address='' height="150" width="150"/>
			     <input type="file" id="chooseImage5" name="file5" >
                 </div>
            </div>
          
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "module/productDetail"
		$("#form-productDetail-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
				descInfo:{
					required:true,
				},
				opeUser:{
					required:true,
				},
				xxxx:{
					required:true,
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	add();
	          /*   $.operate.save(prefix + "/add", $('#form-productDetail-add').serialize()); */
	        }
	    } 
		
		function add(){
			if(!checkProcessType()){
				    var prefix = ctx + "module/productDetail";
				    var form = new FormData(document.getElementById("form-productDetail-add"));
				    $.ajax({  
				        type : 'POST',  
				        url : prefix+"/add",  
				        data: form,
				        processData:false,
		                contentType:false,
				        success : function(result) {  
				        	if(result.code=='0'){
				        		/* console.log("导入成功了") */
				        		$.operate.saveSuccess(result);
				        	}else{
				        		$.modal.alertError("错误提示："+result.msg);
				        	
				        	}
				        },  
				        error : function() {  
				        	$.modal.alertError("错误提示：上传失败，请检查网络后重试,上传文件太大");
			
				        }  
				    });
			}
			
			
		}
		
		function checkProcessType(){
			var flag = false;
			var productCode = $("#productCode").val();
			var processType = $("#processType").val();
			var processTyeName = $("#processType").find("option:selected").text();
			   $.ajax({  
			        type : 'POST',  
			        url : prefix+"/checkProcessType",  
			        data: {"productCode":productCode,"processType":processType},
			        dataType:"json",
			        async : false,
			        success : function(result) {
			        	if(result == 1){
			        		flag = true;
			        		 layer.open({
			        			  title: '提示信息',
			        			  content: "已添加过"+processTyeName+"流程！",
			        			  icon:0
			        			});  
			        	}
			        },   
			    });
			   return flag;
		}
		
		$('#chooseImage1').on('change',function(){
	    	var filePath = $(this).val(),         //获取到input的value，里面是文件的路径
	    		fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),
	    		src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
	    		
	    	// 检查是否是图片
	    	if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {
	    		error_prompt_alert('上传错误,文件格式必须为：png/jpg/jpeg');
	        	return;  
	        }
	        console.log("五张图片来处理吧");
	    	var imagePath1 = $("#image1")[0].src;  
	    	$('#image1').attr('src',src);   	
	     });
		$('#chooseImage2').on('change',function(){
	    	var filePath = $(this).val(),         //获取到input的value，里面是文件的路径
	    		fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),
	    		src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
	    		
	    	// 检查是否是图片
	    	if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {
	    		error_prompt_alert('上传错误,文件格式必须为：png/jpg/jpeg');
	        	return;  
	        }
	        console.log("五张图片来处理吧");
	    	var imagePath2 = $("#image2")[0].src;  
	    	$('#image2').attr('src',src);   	
	     });

		$('#chooseImage3').on('change',function(){
	    	var filePath = $(this).val(),         //获取到input的value，里面是文件的路径
	    		fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),
	    		src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
	    		
	    	// 检查是否是图片
	    	if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {
	    		error_prompt_alert('上传错误,文件格式必须为：png/jpg/jpeg');
	        	return;  
	        }
	        console.log("五张图片来处理吧");
	    	var imagePath1 = $("#image3")[0].src;  
	    	$('#image3').attr('src',src);   	
	     });

		$('#chooseImage4').on('change',function(){
	    	var filePath = $(this).val(),         //获取到input的value，里面是文件的路径
	    		fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),
	    		src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
	    		
	    	// 检查是否是图片
	    	if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {
	    		error_prompt_alert('上传错误,文件格式必须为：png/jpg/jpeg');
	        	return;  
	        }
	        console.log("五张图片来处理吧");
	    	var imagePath1 = $("#image4")[0].src;  
	    	$('#image4').attr('src',src);   	
	     });

		$('#chooseImage5').on('change',function(){
	    	var filePath = $(this).val(),         //获取到input的value，里面是文件的路径
	    		fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),
	    		src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
	    		
	    	// 检查是否是图片
	    	if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {
	    		error_prompt_alert('上传错误,文件格式必须为：png/jpg/jpeg');
	        	return;  
	        }
	        console.log("五张图片来处理吧");
	    	var imagePath1 = $("#image5")[0].src;  
	    	$('#image5').attr('src',src);   	
	     });


	    
	   
	</script>
</body>
</html>
